class Solution
{
public:
    int validSubarraySize(vector<int> &nums, int threshold)
    {
        int n = nums.size();
        vector<int> s;
        s.reserve(n);
        for (int i = 0; i < n; ++i)
        {
            while (!s.empty())
            {
                if (nums[s.back()] >= nums[i])
                {
                    s.pop_back();
                }
                else
                {
                    break;
                }
            }
            s.push_back(i);
            int len = i + 1;
            if (nums[s[0]] > threshold / len)
            {
                return len;
            }
            for (int j = 0; j < s.size() - 1; ++j)
            {
                len = i - s[j];
                if (nums[s[j + 1]] > threshold / len)
                {
                    return len;
                }
            }
        }
        return -1;
    }
};